﻿using BaseUi.Views.MainWindows;
using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi.Views.PlcView
{
    
    /// <summary>
    /// InBoxPpositionView.xaml 的交互逻辑入库定位页面
    /// </summary>
    public partial class InBoxPpositionView : UserControlBase
    {
        private StudentData viewModel = new StudentData();
        public SolidColorBrush RedColor = new SolidColorBrush(Color.FromRgb(255, 69, 0));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220));
        public SolidColorBrush LemonChiffonColor = new SolidColorBrush(Color.FromRgb(255, 250, 205));
        public InBoxPpositionView()
        {
            InitializeComponent();
            DataContext = viewModel;
            viewModel.CommonViewModel = MainWindow4.viewModel.CommonViewModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            getnewnumb();
            Task wartocold = new Task(() =>
            {
                while (true)
                {
                    getfeedcoro();
                    Thread.Sleep(200);
                }
            });
            wartocold.Start();
        }
        
        /// <summary>
        /// 入料皮带正转
        /// </summary>
        private void getfeedcoro()
        {
            var saf = LocalStatic.Plc.Read<bool>("23");
            if (saf.IsSucceed == false)
            {
                viewModel.Feedcoro = RedColor;
                return;
            }
            if (saf.Value)
            {
                viewModel.Feedcoro = LemonChiffonColor;
            }
            else
            {
                viewModel.Feedcoro = BoroColor;
            }
        }
        /// <summary>
        /// 入料皮带
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inboixButton_Click1g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("311", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click1g1z2(object sender, RoutedEventArgs e)
        {

            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("20", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click1g1z3(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }


        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inboixButton_Click1g3z1(object sender, RoutedEventArgs e)
        {
            getnewnumb();
            
        }

        private void getnewnumb()
        {
            var ioi = LocalStatic.Plc.Read<Int16>("0");
            if (ioi.IsSucceed==false)
            {
                inpBox1g1.Text = "未接收";
            }
            else
            {
                inpBox1g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("3");
            if (ioi.IsSucceed == false)
            {
                inpBox1g2.Text = "未接收";
            }
            else
            {
                inpBox1g2.Text = ioi.Value.ToString();
            }
            //inpBox1g1.Text = LocalStatic.Plc.Read<Int16>("0").Value.ToString();
            //inpBox1g2.Text = LocalStatic.Plc.Read<Int16>("3").Value.ToString();
        }

        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inboixButton_Click1g3z2(object sender, RoutedEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(inpBox1g1.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("0", ser);
                ser = Convert.ToInt16(inpBox1g2.Text);
                var ioi2 = LocalStatic.Plc.Write<Int16>("3", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("冷库层上传失败");
                }
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("冷库列上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        private void inboixButton_Click1g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("27", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click1g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("28", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click1g6z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("48", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click1g6z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("48", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        private void inboixButton_Click2g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("36", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("109", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("49", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
        
        private void inboixButton_Click2g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("53", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g5z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("73", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g6z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("90", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click2g6z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("135", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("38", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("54", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("108", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("136", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void inboixButton_Click3g6z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("21", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        

        
    }
}
